/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metro.jme.lottery.util;

import java.util.Vector;
import metro.jme.lottery.exceptions.InvalidFavSetFormatException;

/**
 * This class provides a set of method allowing to check the format of a string
 * @author pierre
 */
public abstract class FormatChecker {

	/**
	 * Method returns true if the format of the string is compliant
	 * @param s
	 * @return 
	 */
	public static boolean checkFormat(String s) {
		try {
			int[] exploded = StringUtil.splitToInt(s, " ");
			for (int i = 0; i < exploded.length; i++) {
				if(exploded[i] <= 0 && exploded[i] > 99) {
					return false;
				}
			}
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/**
	 * Method return true if the string only contains different numbers
	 * @param s
	 * @return 
	 */
	public static boolean checkUniqueness(String s) throws InvalidFavSetFormatException {
		Vector foundPool = new Vector();
		boolean compliant = true;

		if (checkFormat(s)) {
			int[] exploded;
			try {
				exploded = StringUtil.splitToInt(s, " ");
				Integer element;
				for (int i = 0; i < exploded.length; i++) {
					element = new Integer(exploded[i]);
					if (foundPool.indexOf(element) == -1) {
						// Add it to the pool
						foundPool.addElement(element);
					} else {
						throw new InvalidFavSetFormatException("Invalid set format");
						//compliant = false;
					}
				}
			} catch (Exception ex) {
				return false;
			}

		} else {
			throw new InvalidFavSetFormatException("Invalid set format");
		}
		return compliant;
	}
}
